package com.hnkywl.sts.action.report;

import com.hnkywl.sts.entity.organ.Ejzh;
import com.hnkywl.sts.entity.sfgl.Sfk;
import com.hnkywl.sts.service.report.EjzhmxService;
import com.hnkywl.sts.service.sfgl.SkshService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: ccr
 * Date: 14-1-17
 * Time: 上午9:43
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/report/wlz")
public class EjzhmxAction extends SimpleActionSupport {

    private EjzhmxService ejzhmxService;
    private Long gsId;
    private Long khId;
    private Long ejzhId;
    private Date dateStart;
    private Date endDate;
    private Ejzh ejzh;
    private int page;
    private int rows;
    private SkshService skshService;
    private String sfkBm;
    private Sfk sfk;
    private Long nbgsId;

    @Action("ejzhmx")
    public String ejzhmx(){
        endDate = new Date();
        return SUCCESS;
    }
    @Action("ejzhmxList")
    public void ejzhmxList(){
        renderJson(ejzhmxService.findEjzhmx(gsId,khId,endDate,page,rows));
    }

    @Action("ejzhmx_detail")
    public String ejzhyemx(){
        Calendar c = Calendar.getInstance();
        if(c.get(Calendar.DAY_OF_MONTH) <= 1) {
            c.add(Calendar.MONTH,-1);
            dateStart = c.getTime();
        } else {
            c.set(Calendar.DATE,1);
            dateStart = c.getTime();
        }
        endDate = new Date();
        ejzh = ejzhmxService.findEjzh(ejzhId);
        gsId = ejzh.getNbgs().getId();
        return SUCCESS;
    }

    @Action("ejzhyemxList")
    public void ejzhyemxList(){
        if(khId != null) {
            Ejzh ejzh = ejzhmxService.findEjzhByKh(khId,nbgsId);
            if(ejzh != null) {
                ejzhId = ejzh.getId();
            } else {
                renderJson("{\"total\":0,\"rows\":[]}");
                return;
            }
        }
        renderJson(ejzhmxService.findEjzhYeMx(ejzhId, dateStart, endDate, page, rows));
    }

    @Action("ejzhmx_fkmx_detail")
    public String ejzhmxFkmxDetail(){
        sfk  = skshService.findSfkByBm(sfkBm);
        return SUCCESS;
    }

    public Long getGsId() {
        return gsId;
    }

    public void setGsId(Long gsId) {
        this.gsId = gsId;
    }

    public Long getKhId() {
        return khId;
    }

    public void setKhId(Long khId) {
        this.khId = khId;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public Long getEjzhId() {
        return ejzhId;
    }

    public void setEjzhId(Long ejzhId) {
        this.ejzhId = ejzhId;
    }

    public Date getDateStart() {
        return dateStart;
    }

    public void setDateStart(Date dateStart) {
        this.dateStart = dateStart;
    }

    public Ejzh getEjzh() {
        return ejzh;
    }

    public void setEjzh(Ejzh ejzh) {
        this.ejzh = ejzh;
    }

    public String getSfkBm() {
        return sfkBm;
    }

    public void setSfkBm(String sfkBm) {
        this.sfkBm = sfkBm;
    }

    public Sfk getSfk() {
        return sfk;
    }

    public void setSfk(Sfk sfk) {
        this.sfk = sfk;
    }

    public Long getNbgsId() {
        return nbgsId;
    }

    public void setNbgsId(Long nbgsId) {
        this.nbgsId = nbgsId;
    }

    @Autowired
    public void setEjzhmxService(EjzhmxService ejzhmxService) {
        this.ejzhmxService = ejzhmxService;
    }
    @Autowired
    public void setSkshService(SkshService skshService) {
        this.skshService = skshService;
    }
}
